package com.lagou.nio;

import java.nio.ByteBuffer;

/**
 * @Classname ReadOnlyBuffer
 * @Description TODO
 * @Date 2020/7/24 12:46
 * @Created by pc
 */
public class ReadOnlyBuffer  {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(50);
        buffer.putLong(20);
        // 读取, 否则读到的内容为空
        buffer.flip();
        // 获取只读 buffer
        ByteBuffer onlyBuffer = buffer.asReadOnlyBuffer();
        long aLong = onlyBuffer.getLong();
        System.out.println(aLong);

//        onlyBuffer.putLong(23l);
    }
}
